package garin.parse.sql.sql2003;

import garin.parse.MatchToken;
import garin.parse.Token;
import garin.parse.io.Source;

import java.io.IOException;

public class StatementWord extends MatchToken implements StatementOperator {
	private final int length;
	
	public StatementWord(final Token parent, final String word) {
		super(parent, word, false);
		length = word.length();
	}
	
	@Override
	public boolean accept() throws IOException {
		final Source s = source();
		final long at = s.at();
		try {
			if (at > 0) {
				s.go(at - 1);
				if (!s.isWhitespace()) return false;
			}
			s.go(at + length);
			if (!s.isWhitespace()) return false;
		} finally {
			s.go(at);
		}
		return super.accept();
	}
}
